4-1

a. $T(n)=2T(n/2)+n^4$
Let $a=2$, $b=2$, $\epsilon=3$ and $f(n)=n^4=n^{\log_{b}{a}+\epsilon}$. We have $T(n)=a T(n/b)+f(n)$. And since $af(\frac{n}{b}) = 2 (\frac{n}{2})^4=\frac{1}{8}n^4=\frac{1}{8}f(n)$, we can apply case 3 of Master Theorem.
Therefore, $T(n)=\Theta(f(n))=\Theta(n^4)$.

b. $T(n)=T(7n/10)+n$
Let $a=1$, $b=\frac{10}{7}$, $\epsilon=1$ and $f(n)=n=n^{\log_{b}{a}+\epsilon}$. We have $T(n)=a T(n/b)+f(n)$. And since $af(\frac{n}{b}) =\frac{7n}{10}=\frac{7}{10}f(n)$, we can apply case 3 of Master Theorem.
Therefore, $T(n)=\Theta(f(n))=\Theta(n)$.

c. $T(n)=16T(n/4)+n^2$
Let $a=16$, $b=4$ and $f(n)=n^2=n^{\log_{b}{a}}$. We have $T(n)=a T(n/b)+f(n)$. We can apply case 2 of Master Theorem. Therefore, $T(n)=\Theta(n^{\log_{b}{a}} \lg{n}) = \Theta(n^2 \lg{n})$.

d. $T(n)=7T(n/3)+n^2$
Let $a=7$, $b=3$, $\epsilon=2 - \log_{3}{7} > 0$ and $f(n)=n^2=n^{\log_{b}{a}+\epsilon}$. We have $T(n)=a T(n/b)+f(n)$. And since $af(\frac{n}{b}) =7 (\frac{n}{3})^2=\frac{7}{9}f(n)$, we can apply case 3 of Master Theorem. Therefore, $T(n)=\Theta(f(n))=\Theta(n^2)$.

e. $T(n)=7T(n/2)+n^2$
Let $a=7$, $b=2$, $\epsilon=\log_{2}{7}-2 > 0$ and $f(n)=n^2=n^{\log_{b}{a}-\epsilon}$. We have $T(n)=a T(n/b)+f(n)$. We can apply case 1 of Master Theorem.
Therefore, $T(n)=\Theta(n^{\log_{b}{a}})=\Theta(n^{\lg{7}})$.

f. $T(n)=2T(n/4)+\sqrt{n}$
Let $a=2$, $b=4$ and $f(n)=\sqrt{n}=n^{\log_{b}{a}}$. We have $T(n)=a T(n/b)+f(n)$. We can apply case 2 of Master Theorem. Therefore, $T(n)=\Theta(n^{\log_{b}{a}} \lg{n})=\Theta(\sqrt{n} \lg{n})$.

g. $T(n)=T(n-2)+n^2$
Assume T(n) is constant if $n \leq 2$. Then for large enough $n$ be given, with some $\alpha = 1$ or $2$, we have $$T(n) = T(n-2) + n^2 = ... = T(\alpha) + \sum_{k=0}^{\lfloor \frac{n}{2} \rfloor -1}{(n-2k)^2} = T(\alpha) + \sum_{k=0}^{\lfloor \frac{n}{2} \rfloor -1}{(n^2 -4nk + 4k^2)}$$ $= T(\alpha) + (\lfloor \frac{n}{2} \rfloor -1)n^2 + (-4n) \cdot \frac{\lfloor \frac{n}{2} \rfloor(\lfloor \frac{n}{2} \rfloor -1)}{2} + 4 \frac{(\lfloor \frac{n}{2} \rfloor -1)\lfloor \frac{n}{2} \rfloor(2\lfloor \frac{n}{2} \rfloor -1)}{6}$
$= T(\alpha) + (\lfloor \frac{n}{2} \rfloor -1)[n^2 - 2n\lfloor \frac{n}{2} \rfloor + \frac{2}{3} \lfloor \frac{n}{2} \rfloor(2\lfloor \frac{n}{2} \rfloor -1)] \dots (*)$
$\implies \frac{n^3}{48} = (\frac{n}{4})[ \frac{2}{3}(\frac{n}{4})(\frac{n}{2})] \leq (\frac{n}{2} -2)[n^2 - 2n \frac{n}{2} + \frac{2}{3}(\frac{n}{2}-1)(n-3)] \leq (*) \leq (\frac{n}{2})[n^2 - 2n \frac{n}{4} + \frac{2}{3} \frac{n}{2} (2 \cdot \frac{n}{2})] \leq n^3$
(Because $T(\alpha)$ is a constant, it can be dropped when we are estimating upperbound by taking $n$ large enough.)
Therefore, we can conclude that $T(n) = \Omega(n^3)$ and $T(n) = O(n^3)$, hence $T(n) = \Theta(n^3)$.


4-3

a. $T(n)=4T(n/3)+n \lg{n}$
Let $a=4$, $b=3$ and $f(n)=n \lg{n}=O(n^{\log_{b}{a} - \epsilon})$ with $0< \epsilon < -1 + \log_{3}{4}$. (Note that $n\lg^k n = O(n^{k+\eta})$ for all $k \in \mathbb{N}$, $\eta > 0$.)
Then we have $T(n)=a T(n/b)+f(n)$, and we can apply case 1 of Master Theorem. Therefore, $T(n)=\Theta(n^{\log_{b}{a}})=\Theta(n^{\log_{3}{4}})$.

j. $T(n)=\sqrt{n}T(\sqrt{n})+n$
Assume that $T(n)$ is constant if $n \leq N$ for some constant $N>1$. Let $n$ be given (and large enough), $m$ be the smallest natural number s.t. $T(n^{2^{-m}})$ is constant.
Put $b = n^{2^{-m}}$, then $1 < b \leq N$ and $m = \lg \log_{b}{n}$.
$T(n)=\sqrt{n} T(\sqrt{n}) + n$
$ = b^{2^{m-1}}T(b^{2^{m-1}}) + b^{2^{m}}$
$= b^{2^{m-1}} [ b^{2^{m-2}}T(b^{2^{m-2}}) + b^{2^{m-1}} ] + b^{2^{m}}$
$= \dots = T(b)\prod_{k=1}^{m}{b^{2^{m-k}}} + \sum_{k=1}^{m}{\prod_{h=1}^{k}(b^{2^{m-h}} b^{2^{m-k}})} + b^{2^{m}}$
$= T(b)b^{\sum_{k=1}^{m}{2^{m-k}}} + \sum_{k=1}^{m}{b^{2^{m-k}} b^{\sum_{h=1}^{k}{2^{m-h}}}} + b^{2^{m}}$
$= T(b)b^{2^{m}-1} + \sum_{k=1}^{m}{b^{2^{m-k}} b^{2^{m}-2^{m-k}}} + b^{2^{m}}$
$= T(b)b^{2^{m}-1} + m b^{2^{m}} + b^{2^{m}}$
$= T(b) \sqrt{n} + n \lg \log_{b}{n} + n$
$= \Theta(n \lg \lg n)$


4-5

Result $\alpha$ says $\beta$ is $\beta$ says $\alpha$ is Actual state of ($\alpha$,$\beta$)
1 O O (O,O) or (X,X)
2 O X (X,O) or (X,X)
3 X O (O,X) or (X,X)
4 X X (X,O) or (O,X) or (X,X)

Let $A$ be the initial chip set, with $n$ chips and more than $\lfloor \frac{n}{2} \rfloor$ chips are good. Partition $A$ into pairs $(a_1,a_1')$, $(a_2,a_2')$, $\dots$, $(a_j,a_j')$ (and one additional element $a_{j+1}$ if $n$ is odd), with $j = \lfloor \frac{n}{2} \rfloor$. Consider the following algorithm.

For each pair $(a_k,a_k')$:
  If we get testing result 2, 3 or 4, then remove $a_k$ and $a_k'$ from $A$.
  If we get testing result 1, then remove one of $a_k$, $a_k'$ from $A$ in arbitrariness.

Proof of Correctness:
Clearly, we do $\lfloor \frac{n}{2} \rfloor$ tests and remove at least one chip from $A$ for each single test, so $A$ contains at most $\lceil \frac{n}{2} \rceil$ chips after all tests done. To complete the proof, we have to show that $A$ keeps more than good chips than bad chips. Consider a test for pair $(a_k,a_k')$. If the testing result is 2, 3 or 4, it means at least one of $a_k$, $a_k'$ is bad. Hence, there are still more good chips than bad chips in $A$ after removing $a_k$ and $a_k'$. If the testing result is 1, it means either both $a_k$ and $a_k'$ are good or both $a_k$ and $a_k'$ are bad. Since good chips are major in $A$, and note that result 1 is the only possibile outcome for (O,O) pair, thus we must have the same or more quantity of (O,O) pairs than (X,X) pairs with result 1. Therefore, after all tests done, it remains the same or more good chips from result 1 than bad chips from pairs with result 1 in $A$, hence $A$ still holds more good chips than bad chips, and this completes the proof.